// pages/check/check.js
var app = getApp();//引用app.js
var commonURL = app.data.baseURL;
var commonURLYY = app.data.newURL;
var commonURLXX = app.data.lastURL;
Page({
  data: {
    array: [],
    text: '点击选择'
  },
  onLoad: function (options) {
    var that = this;
    that.setData({
      orderno: options.orderno
    })
    wx.request({
      url: commonURL + 'op=shop_hexiao',
      data: {
        uniacid: app.data.GZHid,
        orderno: options.orderno
      },
      success: function (res) {
        that.setData({
          list: res.data.list,
        })
      }
    })
    wx.request({
      url: commonURL + 'op=ztd',
      data: {
        uniacid: app.data.GZHid
      },
      success: function (res) {
        var obj = {};
        var arealist = [];
        for (var i = 0; i < res.data.length; i++) {
          arealist.push(res.data[i].storename);
          if (res.data[i].storename == that.data.list[0].detailed_address){
            that.setData({
              selectIndex: i,
              text: arealist[i]
            })
          }
        }
        console.log(arealist)
        that.setData({
          array: arealist,
          lists: res.data
        })
      }
    })
  },
  bindPickerChange: function (e) {
    this.setData({
      text: this.data.array[e.detail.value],
      selectIndex: e.detail.value
    })
  },
  confirm: function () {
    if (!this.data.gid) {
      wx.showToast({
        title: '请选择商品',
        icon: 'none',
      })
      return
    }
    if (!this.data.selectIndex) {
      wx.showToast({
        title: '请选择自提点',
        icon: 'none',
      })
      return
    }
    wx.request({
      url: commonURL + 'op=write',
      data: {
        openid: app.data.openid,
        uniacid: app.data.GZHid,
        gid: this.data.gid,
        orderno: this.data.orderno,
        areaid: this.data.lists[this.data.selectIndex].id
      },
      success: function (res) {
        if (res.data.status == 1) {
          wx.showModal({
            title: '提示',
            showCancel: false,
            content: '核销成功',
            complete: function (res) {
              wx.navigateBack({})
            }
          })
        } else {
          wx.showModal({
            title: '提示',
            content: '核销失败',
            showCancel: false,
            complete: function (res) {
              wx.navigateBack({})
            }
          })
        }
      }
    })
  },
  cancel: function () {
    wx.navigateBack({})
  },
  checkboxChange: function (e) {
    console.log(e)
    this.setData({
      gid: e.detail.value
    })
  },
  onReady: function () {

  },
  onShow: function () {

  },

  /**
  * 生命周期函数--监听页面隐藏
  */
  onHide: function () {

  },

  /**
  * 生命周期函数--监听页面卸载
  */
  onUnload: function () {

  },

  /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
  onPullDownRefresh: function () {

  },
})